package com.ymatou.livevideo.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymatou.livevideo.parameter.LiveNotifyBean;
import com.ymatou.livevideo.parameter.RecLiveNotifyBean;
import com.ymatou.livevideo.parameter.StreamLiveNotifyBean;
import com.ymatou.livevideo.service.LiveNotifyCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

/**
 * 直播第三方回调通知 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_LiveNotify {
	private static StreamLiveNotifyBean streamlivenotifyBean;
	private static LiveNotifyCall livenotifyCall;
	private static LiveRoomWapper liveroomwapper;
	private static RecLiveNotifyBean recivenotifyBean;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("直播第三方回调通知");
	}

	@Before
	public void caseUp() {
		streamlivenotifyBean = new StreamLiveNotifyBean();
		livenotifyCall = new LiveNotifyCall();
		liveroomwapper = new LiveRoomWapper();
		recivenotifyBean = new RecLiveNotifyBean();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(livenotifyCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LiveNotify_001() {
		Logger.start(true, "直播第三方回调通知成功推流");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 1);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(2, dbliveroom.getLiveStatus(), "验证LiveStatus");
			Logger.verifyEquals(1, dbliveroom.getLivePush(), "验证LivePush");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LiveNotify_002() {
		Logger.start(true, "直播第三方回调通知成功断流");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再断流");
			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 1);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();

			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 0);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(3, dbliveroom.getLiveStatus(), "验证LiveStatus");
			Logger.verifyEquals(1, dbliveroom.getLivePush(), "验证LivePush");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LiveNotify_003() {
		Logger.start(true, "直播第三方回调通知成功新的录制文件已生成");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			livenotifyCall.setData(recivenotifyBean);
			livenotifyCall.callService();

			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(recivenotifyBean.getVideo_url(), dbliveroom.getHistoryPlayUrl(), "验证LiveStatus");
			liveroomwapper.selectLivereplayById(dbliveroom.getId().toString());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	@Ignore
	public void Tc_LiveNotify_004() {
		Logger.start(true, "直播第三方回调通知成功新的截图文件已生成");
		try {
			// TODO 补全case代码
			org.junit.Assert.fail();
			// livenotifyCall.setData(livenotifyBean);
			livenotifyCall.callService();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LiveNotify_005() {
		Logger.start(true, "签名错误失败");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 1);
			streamlivenotifyBean.setSign("1");
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("500", livenotifyCall.getString("code"), "验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LiveNotify_006() {
		Logger.start(true, "未推流直播第三方回调通知成功断流,状态不变0->0");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 0);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(0, dbliveroom.getLiveStatus(), "验证LiveStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LiveNotify_007() {
		Logger.start(true, "系统自动关闭直播7不再接受直播第三方回调通知成功推流变更");
		try {
			int updatestatus = 7;
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			liveroomwapper.updateLiveRoomPushStatus(liveroom.getId(), updatestatus);

			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 1);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(updatestatus, dbliveroom.getLiveStatus(), "验证LiveStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LiveNotify_008() {
		Logger.start(true, "系统自动关闭直播7不再接受直播第三方回调通知成功断流变更");
		try {
			int updatestatus = 7;
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			liveroomwapper.updateLiveRoomPushStatus(liveroom.getId(), updatestatus);

			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 0);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(updatestatus, dbliveroom.getLiveStatus(), "验证LiveStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LiveNotify_009() {
		Logger.start(true, "直播第三方回调通知成功断流再推流成功");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再断流再推流");
			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 1);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();

			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 0);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();

			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 1);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(2, dbliveroom.getLiveStatus(), "验证LiveStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LiveNotify_010() {
		Logger.start(true, "关闭直播8不再接受直播第三方回调通知成功推流变更");
		try {
			int updatestatus = 8;
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			liveroomwapper.updateLiveRoomPushStatus(liveroom.getId(), updatestatus);

			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 1);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(updatestatus, dbliveroom.getLiveStatus(), "验证LiveStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LiveNotify_011() {
		Logger.start(true, "结束直播9不再接受直播第三方回调通知成功推流变更");
		try {
			int updatestatus = 9;
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			liveroomwapper.updateLiveRoomPushStatus(liveroom.getId(), updatestatus);

			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 1);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(updatestatus, dbliveroom.getLiveStatus(), "验证LiveStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LiveNotify_012() {
		Logger.start(true, "强制关停10不再接受直播第三方回调通知成功推流变更");
		try {
			int updatestatus = 10;
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			liveroomwapper.updateLiveRoomPushStatus(liveroom.getId(), updatestatus);

			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 1);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(updatestatus, dbliveroom.getLiveStatus(), "验证LiveStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LiveNotify_013() {
		Logger.start(true, "关闭直播8不再接受直播第三方回调通知成功断流变更");
		try {
			int updatestatus = 8;
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			liveroomwapper.updateLiveRoomPushStatus(liveroom.getId(), updatestatus);

			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 0);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(updatestatus, dbliveroom.getLiveStatus(), "验证LiveStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LiveNotify_014() {
		Logger.start(true, "结束直播9不再接受直播第三方回调通知成功断流变更");
		try {
			int updatestatus = 9;
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			liveroomwapper.updateLiveRoomPushStatus(liveroom.getId(), updatestatus);

			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 0);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(updatestatus, dbliveroom.getLiveStatus(), "验证LiveStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LiveNotify_015() {
		Logger.start(true, "强制关停10不再接受直播第三方回调通知成功断流变更");
		try {
			int updatestatus = 10;
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			liveroomwapper.updateLiveRoomPushStatus(liveroom.getId(), updatestatus);

			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 0);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(updatestatus, dbliveroom.getLiveStatus(), "验证LiveStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}